package com.online.music.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.online.music.common.Result;
import com.online.music.entity.vo.SongPageVo;
import com.online.music.entity.vo.SongVo;
import com.online.music.entity.dto.SongDTO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

import com.online.music.service.ISongService;
import com.online.music.entity.po.Song;

import org.springframework.web.bind.annotation.RestController;


/**
 * @Author: Leno
 * @Date: 2025-01-31
 * @Description: song接口
 */
@RequiredArgsConstructor
@Slf4j
@Tag(name = "song接口")
@RestController
@RequestMapping("/song")
public class SongController {

    private final ISongService songService;

    @Operation(summary = "查询所有Song")
    @GetMapping
    public Result<List<Song>> findAll() {
        return Result.success(songService.list());
    }

    @Operation(summary = "根据id查询Song")
    @GetMapping("/{id}")
    public Result<SongVo> findOne(@PathVariable Long id) {
        return songService.findById(id);
    }

    @Operation(summary = "根据分页查询Song")
    @GetMapping("/page")
    public Result<Page<SongPageVo>> findPage(@RequestParam Integer pageNum, @RequestParam Integer pageSize, Song song) {
        return songService.findPage(pageNum, pageSize, song);
    }

    @Operation(summary = "添加或修改Song")
    @PostMapping
    public Result<Boolean> save(@RequestBody SongDTO songDTO) {
        return songService.addOrUpdate(songDTO);
    }

    @Operation(summary = "根据id批量删除Song")
    @DeleteMapping("/del/batch")
    public Result<String> deleteBatch(@RequestBody List<Long> ids) {
        return songService.deleteBatch(ids);
    }

    @Operation(summary = "审核通过")
    @GetMapping("/pass/{id}")
    public Result<Void> pass(@PathVariable Long id) {
        return songService.lambdaUpdate()
                .set(Song::getStatus, 1)
                .set(Song::getBackReason, null)
                .eq(Song::getId, id).update()
                ? Result.successMsg("审核通过") : Result.error("审核失败");
    }

    @Operation(summary = "驳回")
    @PutMapping("/reject")
    public Result<Void> pass(@RequestBody Song song) {
        return songService.lambdaUpdate()
                .set(Song::getStatus, 2)
                .set(Song::getBackReason, song.getBackReason())
                .eq(Song::getId, song.getId()).update()
                ? Result.successMsg("驳回成功") : Result.error("驳回失败");
    }

    @Operation(summary = "举报歌曲")
    @GetMapping("/report/{songId}")
    public Result<Void> report(@PathVariable Long songId) {
        return songService.report(songId);
    }

}
